﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ReadCSV;
namespace Main
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DoiTuong oj;
        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        void loadData(string url)
        {
            oj = new DoiTuong(url);
            listData.Clear();
            int m = listData.Width / oj.nThuocTinh;
            for (int i = 0; i < oj.nThuocTinh; i++)
                listData.Columns.Add(oj.TenThuocTinh[i], m);
            for (int i = 0; i < oj.nMau; i++)
            {
                ListViewItem listtemp;
                string[] a = new string[oj.nThuocTinh];
                for (int j = 0; j < oj.nThuocTinh; j++)
                {
                    //listtemp.SubItems.Add(oj.List[i][j]);                    
                    a[j] = oj.List[i][j];                 
                }
                listtemp = new ListViewItem(a);
                listData.Items.Add(listtemp);
            }
        }

        private void butChon_Click(object sender, EventArgs e)
        {
            string temp = "";
            OpenFileDialog ofi = new OpenFileDialog();
            ofi.Filter = "CSV File|*.csv|All Files|*.*";
            if (ofi.ShowDialog() == DialogResult.OK)
            {
                temp = ofi.FileName;
                textURL.Text = temp;
            }
            loadData(temp);
        }
    }
}
